/**
 * 组合模式：把一组相似的对象当作一个单一的对象，使得用户可以一致地对待单个对象和对象组合
 * 
 * 示例需求：
 * 有一个类 Employee，该类被当作组合模型类。
 * CompositePatternDemo 类使用 Employee 类来添加部门层次结构，并打印所有员工。
 * 
 * 角色：
 * 复合节点：Employee
 * 客户端：Simple
 *
 * 观察角色可知，本次实例确实两个角色：组件接口、叶子节点。其实本次示例为简单示例，把组件接口省略，同时每个Employee既是【复合节点】也是【叶子节点】。
 */
public class SimpleMain {
    public static void main(String[] args) {
        Employee CEO = new Employee("John", "CEO", 30000);

        Employee headSales = new Employee("Robert", "Head Sales", 20000);

        Employee headMarketing = new Employee("Michel", "Head Marketing", 20000);

        Employee clerk1 = new Employee("Laura", "Marketing", 10000);
        Employee clerk2 = new Employee("Bob", "Marketing", 10000);

        Employee salesExecutive1 = new Employee("Richard", "Sales", 10000);
        Employee salesExecutive2 = new Employee("Rob", "Sales", 10000);

        CEO.add(headSales);
        CEO.add(headMarketing);

        headSales.add(salesExecutive1);
        headSales.add(salesExecutive2);

        headMarketing.add(clerk1);
        headMarketing.add(clerk2);

        // 打印该组织的所有员工
        System.out.println(CEO);
        for (Employee headEmployee : CEO.getSubordinates()) {
            System.out.println(headEmployee);
            for (Employee employee : headEmployee.getSubordinates()) {
                System.out.println(employee);
            }
        }
    }
}
